import { Component, OnInit, Output, Input, EventEmitter, ViewChild } from '@angular/core';
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { NzModalRef, NzFormatEmitEvent, NzModalService, NzTreeComponent, NzTreeNodeOptions, NzMessageService } from 'ng-zorro-antd';
import { PagesService } from '../../services/pages.service';
import { UtilService } from '../../services/util.service';
import { RequestService } from '../../services/request.service';
declare var layui: any;
declare var layer: any;
declare var $: any;

@Component({
  selector: 'app-sla',
  templateUrl: './sla.component.html',
  styleUrls: ['./sla.component.scss']
})
export class SlaComponent implements OnInit {

  constructor(public router: Router, private http: HttpClient, public interfaceService: PagesService, public utilService: UtilService, public request: RequestService) {

  }

  @Output() private outer = new EventEmitter();
  @Input() puc_msg: any;

  unitStatus_list = JSON.parse(localStorage.getItem("unitStatus_list"))
  prodStatus_list = JSON.parse(localStorage.getItem("prodStatus_list"))
  progress_list;
  slaType_list;
  rqdCtrl_list;
  bxiEnabled_list;
  ordType_list;

  ngOnInit() {
    setTimeout(()=>{ 
      this.interfaceService.postPage("/erp/purchase/prc/option", {}).subscribe((data0: any) => {//手动下拉
        if (this.interfaceService.codeValidation(data0)) {
        if (data0.code == 200) {
          var sele = data0.object;
          this.progress_list = sele.progress;//进度
          /* this.slaType_list = sele.slaType;//销售申请类别
          this.rqdCtrl_list = sele.rqdCtrl;//货期控制
          this.bxiEnabled_list = sele.bxiEnabled;//启用配码
          this.ordType_list = sele.ordType;//订单类别 */
        }
      }
      });
    },500);
  }

  popup01_url = '';
  popup01_switchUnitId = '';
  popup01 = false;
  popup01_show(url, switchUnitId): void {
    this.popup01_url = url
    this.popup01_switchUnitId = switchUnitId;
    this.popup01 = true;
    this.popup01_table();
  }
  popup01_hide(): void {
    this.popup01 = false;
    this.popup01_url = '';
    this.popup01_ss1 = '';
    this.popup01_ss2 = '';
    this.popup01_ss3 = '';
    this.popup01_ss4 = '';
    this.popup01_ss5 = '';
    this.popup01_ss7 = null;
  }

  venderIdss = '';
  popup01_ss1 = '';
  popup01_ss2 = '';
  popup01_ss3 = '';
  popup01_ss4 = '';
  popup01_ss5 = '';
  popup01_ss7 = null;
  popup01_table() {
    var jindu = this.popup01_ss7
    if (this.popup01_ss7 == null) {
      jindu = ""
    } else {
      jindu = this.popup01_ss7
    }
    this.popup01_listTable(this.popup01_url + "?1=1&slaNum=" + this.popup01_ss1 + "&startTime=" + this.popup01_ss2 + "&endTime=" + this.popup01_ss3 + "&vendeeNum=" + this.popup01_ss4 + "&delivWarehNum=" + this.popup01_ss5 + "&progress=" + jindu + "&switchUnitId=" + this.popup01_switchUnitId);
  }

  popup01_listTable(url): void {
    setTimeout(() => {
      layui.use(['table',  'laydate'], (obj) => {
        var  table = layui.table,  laydate = layui.laydate;
        laydate.render({
          elem: '#popup011_ss2'
          , done: (value) => {
            this.popup01_ss2 = value;
          }
        });
        laydate.render({
          elem: '#popup011_ss3'
          , done: (value) => {
            this.popup01_ss3 = value;
          }
        });
        table.render({
          elem: '#popup01_tblist_sla'
          , height: this.utilService.height
          , width: 680
          , url: url
          , page: true //开启分页
          , limit: 15
          , limits: this.utilService.limits
          , title: '数据表'
          , cellMinWidth: 150
          , cols: [[
            { title: '序号', type: 'numbers', fixed: 'left' }
            , { field: 'unitId', title: '组织Id', hide: true }
            , { field: 'delivWarehId', title: '发货仓库ID', hide: true }
            , { field: 'deptId', title: '部门ID', hide: true }
            , { field: 'stUnitId', title: '始发方ID', hide: true }
            , { field: 'venderId', title: '供应商ID', hide: true }
            , { field: 'rcvWarehId', title: '收货仓库ID', hide: true }
            , { field: 'endUnitId', title: '转送方ID', hide: true }
            , { field: 'endWarehId', title: '转送仓库ID', hide: true }
            , { field: 'chkrId', title: '操作员ID', hide: true }
            , { field: 'unitId', title: '审核人ID', hide: true }
            , { field: 'vendeeId', title: '采购商id', hide: true }




            , { field: 'slaNum', title: '销售申请号' }
            , { field: 'psxNum', title: '购销申请号' }
            , {
              field: 'slaType', title: '销售申请类别',
              templet: (d) => {
                return this.utilService.table_select(d.slaType, this.slaType_list);
              }
            }
            , { field: 'docDate', title: '单据日期' }
            , { field: 'vendeeNum', title: '采购商编号' }
            , { field: 'vendeeName', title: '采购商名称' }
            , { field: 'rcvWarehNum', title: '收货仓库编号' }
            , { field: 'rcvWarehName', title: '收货仓库名称' }
            , { field: 'deptNum', title: '部门编号' }
            , { field: 'deptName', title: '部门名称' }
            , { field: 'endUnitNum', title: '转送方编号' }
            , { field: 'endUnitName', title: '转送方名称' }
            , { field: 'endWarehNum', title: '转送仓库编号' }
            , { field: 'endWarehName', title: '转送仓库名称' }
            , { field: 'vdeInvd', title: '采购商介入' }
            , { field: 'puaAutoGen', title: '采购申请自动生成' }
            , { field: 'puaGen', title: '采购申请已生成' }
            , { field: 'puaAutoChk', title: '采购申请自动审核' }

            , { field: 'delivWarehNum', title: '发货仓库编号' }
            , { field: 'delivWarehName', title: '发货仓库名称' }
            , { field: 'stUnitNum', title: '始发方编号' }
            , { field: 'stUnitName', title: '始发方名称' }
            , { field: 'stWarehNum', title: '始发仓库编号' }
            , { field: 'stWarehName', title: '始发仓库名称' }
            , { field: 'slaAutoGen', title: '销售申请自动生成' }

            , { field: 'slaGen', title: '销售申请已生成' }
            , { field: 'slaAutoChk', title: '销售申请自动审核' }
            , {
              field: 'rqdCtrl', title: '货期控制',
              templet: (d) => {
                return this.utilService.table_select(d.rqdCtrl, this.rqdCtrl_list);
              }
            }
            , { field: 'prodCatId', title: '商品分类ID' }
            , { field: 'prodCatName', title: '商品分类名称' }
            , {
              field: 'ordType', title: '订单类别',
              templet: (d) => {
                return this.utilService.table_select(d.ordType, this.ordType_list);
              }
            }
            , { field: 'reqdDate', title: '货期' }
            , {
              field: 'bxiEnabled', title: '启用配码',
              templet: (d) => {
                return this.utilService.table_select(d.bxiEnabled, this.bxiEnabled_list);
              }
            }
            , { field: 'ttlQty ', title: '总数量' }
            , { field: 'ttlBox', title: '总箱数' }
            , { field: 'ttlVal', title: '总金额' }
            , { field: 'ttlMkv', title: '总市值' }
            , { field: 'oprCode', title: '操作员代码' }
            , { field: 'aaaa', title: '操作员姓名' }
            , { field: 'opTime', title: '操作时间' }
            , { field: 'chkrNum', title: '审核人编号' }
            , { field: 'chkrName', title: '审核人姓名' }
            , { field: 'chkTime', title: '审核时间' }
            , {
              field: 'progress', title: '进度',
              templet: (d) => {
                return this.utilService.table_select(d.progress, this.progress_list);
              }
            }
            , { field: 'effective', title: '已生效' }
            , { field: 'suspended', title: '挂起' }
            , { field: 'cancelled', title: '撤销' }
            , { field: 'remarks', title: '备注' }
          ]]
          , request: {
            pageName: 'page' //页码的参数名称，默认：page
            , limitName: 'size' //每页数据量的参数名，默认：limit
          }
          , parseData: function (res) { //res 即为原始返回的数据
            return {
              "code": res.code, //解析接口状态
              "msg": res.message, //解析提示文本
              "count": res.object.total, //解析数据长度
              "data": res.object.list //解析数据列表
            }
          }
          , response: {
            statusCode: 200 //规定成功的状态码，默认：0
            , dataName: 'data' //规定数据列表的字段名称，默认：data
          }
        });
        table.on('rowDouble(popup01_tblist_sla)', (obj) => {
          this.popup01_hide();
          this.outer.emit(obj.data)
        });

      });

    }, 50);

  }



  @ViewChild('unitsChild') units: any; //组织
  popup0_id = 0
  popup0_url = ""
  popup0_show(id, type): void {
    this.popup0_id = id
    this.popup0_url = "&unitType=" + type + "&switchUnitId=" + this.popup01_switchUnitId
    if (this.popup0_id == 1) {
      this.popup0_url = "&switchUnitId=" + this.popup01_switchUnitId
    } else if (this.popup0_id == 2) {
      this.popup0_url = "&switchUnitId=" + this.popup01_switchUnitId
    } 
    this.units.popup01_show("/erp/unit/option/unitOption?unitType=" + type + this.popup0_url);
  }

  unitsParent(e) {		//接收子组件传递过来的数据
    if (this.popup0_id == 1) {
      this.popup01_ss4 = e.unitCode;
    } else if (this.popup0_id == 2) {
      this.popup01_ss5 = e.unitCode;
    } 
  }



}
